<template>
  <div style="margin-bottom: 150px">
    <div>
      <div class="info-item">
        <TitleBox
          style="width: 95%; margin-bottom: 35px"
          title="基本信息"
        ></TitleBox>
        <div style="width: 100%; display: flex; justify-content: center"
          ><a-form style="width: 60%" :model="taskData" auto-label-width>
            <a-row :gutter="24" justify="space-between">
              <a-col :span="11">
                <a-form-item field="posts.post2" label="收货单号:"
                  ><a-input disabled style="width: 320px" v-model="form.number"
                /></a-form-item>
              </a-col>
              <a-col :span="11">
                <a-form-item
                  v-if="form.entryType === 1"
                  label="关联采购订单号："
                >
                  <a-input
                    disabled
                    style="width: 320px"
                    v-model="form.outsourcingNumber"
                  />
                </a-form-item>
                <a-form-item v-if="form.entryType === 2" label="关联委外单号：">
                  <a-input
                    disabled
                    style="width: 320px"
                    v-model="form.outsourcingNumber"
                  />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="24" justify="space-between">
              <a-col :span="11">
                <a-form-item field="posts.post2" label="供应商编码:"
                  ><a-input
                    disabled
                    style="width: 320px"
                    v-model="form.supplierNumber"
                    placeholder=""
                    allow-clear
                /></a-form-item>
              </a-col>
              <a-col :span="11">
                <a-form-item field="posts.post2" label="供应商名称："
                  ><a-input
                    :style="{ width: '320px' }"
                    v-model="form.supplierName"
                    disabled
                    allow-clear
                /></a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="24" justify="space-between">
              <a-col :span="11">
                <a-form-item field="posts.post2" label="收货人：">
                  <a-select
                    v-model="form.entryStaffId"
                    disabled
                    :style="{ width: '320px' }"
                    placeholder="请选择任务负责人"
                    @change="getUserInfo"
                  >
                    <a-option
                      v-for="item in Personne"
                      :key="item.id"
                      :value="item.id"
                      >{{ item.name }}</a-option
                    >
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="11">
                <a-form-item field="posts.post2" label="收货日期：">
                  <a-date-picker
                    v-model="form.entryDate"
                    style="width: 200px"
                    disabled
                  />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-item field="posts.post2" label="暂存区域：">
                  <a-textarea disabled v-model="form.location" allow-clear />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-item field="posts.post2" label="备注：">
                  <a-textarea disabled v-model="form.remark" allow-clear />
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- <div style="width: 100%; display: flex; margin: 20px 50px">
          <a-space>
            <div
              style="
                width: 4px;
                height: 15px;
                background-color: rgba(61, 126, 255, 1);
                border: none;
                border-radius: 2px;
              "
            >
            </div>
            <h3>质检与入库信息</h3>
          </a-space>
        </div> -->
        <!-- <div style="width: 100%; display: flex; justify-content: center"
          ><a-form
            style="width: 60%; margin-left: 100px"
            :model="taskData.form"
            auto-label-width
          >
            <a-row :gutter="24" justify="space-between">
              <a-col :span="12">
                <a-form-item field="posts.post2" label="质检员：">
                  <a-space>
                    <a-tooltip
                      content="注：可以直接选择质检员下发质检任务，如不指定则直接进入“来料质检任务”待检任务中。"
                      position="top"
                    >
                      <icon-exclamation-circle-fill
                        style="font-size: 20px; color: blue"
                      />
                    </a-tooltip>

                    <a-select
                      disabled
                      :style="{ width: '320px' }"
                      v-model="form.inspectionStaffId"
                      @change="getUserInfo"
                    >
                      <a-option
                        v-for="item in Personne"
                        :key="item.id"
                        :value="item.id"
                        >{{ item.name }}</a-option
                      >
                    </a-select>
                  </a-space>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item field="posts.post2" label="仓管员：">
                  <a-select
                    disabled
                    :style="{ width: '320px' }"
                    v-model="form.warehouseStaffId"
                    @change="getUserInfo"
                  >
                    <a-option
                      v-for="item in Personne"
                      :key="item.id"
                      :value="item.id"
                      >{{ item.name }}</a-option
                    >
                  </a-select></a-form-item
                >
              </a-col>
            </a-row>
          </a-form>
        </div> -->
        <TitleBox
          style="width: 95%; margin-bottom: 35px"
          title="收货明细"
        ></TitleBox>
        <div
          style="
            width: 90%;
            margin-left: 5%;
            box-shadow: 1px 1px 5px rgb(153 153 153 / 35%);
            border-radius: 4px;
          "
        >
          <div style="padding: 30px">
            <div style="text-align: right" class="button-item"></div
            ><tableTurn
              v-if="form.purchaseOrderProduct"
              style="margin-top: 10px"
              :table-data="getProduct"
              ref="tableRef"
              :pagination="false"
              :args="args"
            >
              <a-table-column :width="80" align="center">
                <template #title> 序号 </template>
                <template #cell="{ rowIndex }">
                  <div style="position: relative">
                    <div>{{ rowIndex + 1 }}</div>
                  </div>
                </template>
              </a-table-column>
              <a-table-column
                align="center"
                :width="80"
                title="物料编码"
                data-index="productNumber"
              >
              </a-table-column>
              <a-table-column
                align="center"
                :width="80"
                title="物料名称"
                data-index="productName"
              >
              </a-table-column>

              <a-table-column
                align="center"
                :width="80"
                title="规格型号"
                data-index="spec"
              >
              </a-table-column>
              <a-table-column
                align="center"
                title="基本单位"
                data-index="amount"
                :width="80"
              >
              </a-table-column>

              <a-table-column
                align="center"
                :width="80"
                title="订单数量"
                data-index="totalAmount"
              >
              </a-table-column>
              <a-table-column
                align="center"
                :width="80"
                title="已来料数量"
                data-index="receivedAmount"
              >
              </a-table-column>

              <a-table-column
                align="center"
                :width="80"
                title="优先级"
                data-index="spec"
              >
                <template #cell="{ record }">
                  <a-select
                    disabled
                    v-model="record.level"
                    placeholder="Please select ..."
                  >
                    <a-option :value="1">低</a-option>
                    <a-option :value="2">中</a-option>
                    <a-option :value="3">高</a-option>
                    <a-option :value="4">紧急</a-option>
                  </a-select>
                </template>
              </a-table-column>
            </tableTurn></div
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import {
    reactive,
    ref,
    computed,
    onMounted,
    defineAsyncComponent,
  } from 'vue';
  import { useRoute } from 'vue-router';
  import {
    getPurchaseOrderList,
    getSinglePurchaseOrder,
  } from '@/api/buy-management/buy-order/index';
  import {
    GetPersonnelinformation,
    Getsingleperson,
  } from '@/api/home/System settings/personal-information/index';
  import { getWarehouseEntrySingle } from '@/api/inventory-management/warehousing-management/receiving-management/index';
  import { cloneDeep } from 'lodash';

  const route = useRoute();
  const id = Number(route.query.id);

  // 获取人员信息
  const Personne = ref();
  const Personnelinformation = async () => {
    const res = await GetPersonnelinformation({ page: 0, size: -1 });
    Personne.value = res.content.data;
  };
  Personnelinformation();

  const tableRef = ref();

  const form = ref<any>({
    // number: undefined,
    // purchaseOrderNumber: undefined,
    // entryType: undefined,
    // supplierId: undefined,
    // supplierName: undefined,
    // purchaseStaffId: undefined,
    // purchaseStaffName: undefined,
    // entryStaffId: undefined,
    // warehouseStaffId: undefined,
    // inspectionStaffId: undefined,
    // location: '',
    // remark: '',
    // state: 1,
    // purchaseOrderProduct: [],
    // StaffPhone: '',
    // salesmanName: '',
  });

  const getData = async () => {
    const res = await getWarehouseEntrySingle({ id });
    form.value = res;
  };
  getData();

  // 表格配置
  const args = reactive({
    stripe: false,
    scroll: {
      y: 2000,
      x: 500,
    },
    bordered: {
      headerCell: true,
    },
    rowKey: 'id', // 批量选择按钮 以合同名称来作为key
  });

  let taskData = reactive<any>({
    form: {},
  });

  const getProduct = () => {
    try {
      return Promise.resolve(form.value.purchaseOrderProduct);
    } catch (err: unknown) {
      console.log(err);
    }
  };

  const BuyOrderList = ref();
  const getBuyOrderList = async () => {
    const res = await getPurchaseOrderList({ page: 1, size: -1 });
    BuyOrderList.value = res.content;
  };
  getBuyOrderList();
  const isSelectSupplier = ref(false);

  const getInfo = async (id: number) => {
    const res = await getSinglePurchaseOrder({ id });
    form.value.purchaseStaffId = res.salesman;
    form.value.purchaseStaffName = res.salesmanName;
    form.value.supplierId = res.supplierId;
    form.value.supplierName = res.supplierName;
    form.value.purchaseOrderProduct = res.product;
    tableRef.value.loadData();
  };

  const getUserInfo = async (id: any) => {
    const res = await Getsingleperson({ id });
    form.value.StaffPhone = res.mobile;
  };
</script>

<style scoped lang="less">
  .basic-item {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(242, 243, 245, 0.852);
  }

  .title {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .title-item {
    width: 95%;
    height: 60px;
    margin: auto;
    background-color: rgba(245, 247, 250);
    line-height: 60px;
    margin-top: 20px;
  }

  .info-item {
    width: 100%;
  }

  .report-item {
    width: 95%;
    height: 60px;
    margin: auto;
    background-color: rgba(245, 247, 250);
    line-height: 60px;
  }

  .custom-radio-card {
    padding: 10px 16px;
    border: 1px solid var(--color-border-2);
    border-radius: 4px;
    width: 150px;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    height: 40px;
    line-height: 40px;
    display: flex;
  }

  .custom-radio-card-masky {
    height: 17px;
    width: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 100%;
    border: 1px solid var(--color-border-2);
    box-sizing: border-box;
    margin-left: 30%;
  }

  .custom-radio-card-maskn {
    height: 17px;
    width: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 100%;
    border: 1px solid var(--color-border-2);
    box-sizing: border-box;
    margin-left: 30%;
  }

  .custom-radio-card-mask-dot {
    width: 8px;
    height: 8px;
    border-radius: 100%;
  }

  .custom-radio-card-title {
    color: var(--color-text-1);
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 8px;
  }

  .custom-radio-card-shade {
    width: 45px;
    height: 38px;
    border-right: 1px solid var(--color-border-2);
    background-color: white;
    box-sizing: border-box;
  }

  .custom-radio-card-shadey {
    width: 105px;
    height: 38px;
    background-color: white;
    box-sizing: border-box;
  }

  .custom-radio-card-shaden {
    width: 105px;
    height: 38px;
    background-color: white;
    box-sizing: border-box;
  }

  .custom-radio-card-checked .custom-radio-card-masky {
    border-color: rgb(49, 194, 124);
  }

  .custom-radio-card-checked .custom-radio-card-maskn {
    border-color: rgb(255, 153, 0);
  }

  .custom-radio-card-checked .custom-radio-card-shadey {
    // background-color: var(--color-primary-light-1);
    // ba-color: rgb(49, 194, 124);
    color: white;
    background-color: rgb(49, 194, 124);
  }

  .custom-radio-card-checked .custom-radio-card-shaden {
    // background-color: var(--color-primary-light-1);
    // ba-color: rgb(49, 194, 124);
    color: white;
    background-color: rgb(255, 153, 0);
  }

  .custom-radio-card:hover .custom-radio-card-title,
  .custom-radio-card-checked .custom-radio-card-title {
    color: rgb(var(--primary-6));
  }

  .custom-radio-card-checked .custom-radio-card-mask-dot {
    background-color: rgb(var(--primary-6));
  }

  // .WaitSubmitted {
  //   // 待下达
  //   width: 95px;
  //   height: 40px;
  //   border-radius: 100px;
  //   line-height: 40px;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  //   background: #c9cdd4;
  //   color: rgb(255, 255, 255);
  //   border: none;
  // }

  // .Examining {
  //   // 执行中
  //   width: 95px;
  //   height: 40px;
  //   border-radius: 100px;
  //   line-height: 40px;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  //   background: #165dff;
  //   border: none;
  //   color: aliceblue;
  // }

  // .Pass {
  //   // 已通过
  //   width: 95px;
  //   height: 40px;
  //   border-radius: 100px;
  //   line-height: 40px;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  //   background-color: rgba(49, 194, 124);
  //   border: none;
  //   color: aliceblue;
  // }

  // .NoPass {
  //   //不通过
  //   width: 95px;
  //   height: 40px;
  //   border-radius: 100px;
  //   line-height: 40px;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  //   background: #f53f3f;
  //   border: none;
  // }

  // .Qualified {
  //   // 待执行
  //   width: 95px;
  //   height: 40px;
  //   border-radius: 100px;
  //   line-height: 40px;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  //   background: rgba(255, 247, 232);
  //   border: none;
  //   color: #ff9a2e;
  // }

  // .Urgent {
  //   width: 73px;
  //   height: 40px;
  //   background: inherit;
  //   border-radius: 5px;
  //   border-width: 1px;
  //   border-style: solid;
  //   box-shadow: none;
  //   font-size: 16px;
  //   border-color: rgba(255, 0, 0, 1);
  //   background-color: rgba(255, 236, 232, 1);
  //   color: #f53f3f;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  // }

  // .low {
  //   width: 73px;
  //   height: 40px;
  //   background: inherit;
  //   border-radius: 5px;
  //   border-width: 1px;
  //   border-style: solid;
  //   box-shadow: none;
  //   font-size: 16px;
  //   border-color: #b3b3b3;
  //   background-color: #cccccc62;
  //   color: #b3b3b3;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  // }

  // .centre {
  //   width: 73px;
  //   height: 40px;
  //   background: inherit;
  //   border-radius: 5px;
  //   border-width: 1px;
  //   border-style: solid;
  //   box-shadow: none;
  //   font-size: 16px;
  //   border-color: #ff7d00;
  //   background-color: #ff7b0073;
  //   color: #ff7d00;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  // }

  // .Tall {
  //   width: 73px;
  //   height: 40px;
  //   background: inherit;
  //   border-radius: 5px;
  //   border-width: 1px;
  //   border-style: solid;
  //   box-shadow: none;
  //   font-size: 16px;
  //   border-color: #ff7d00;
  //   background-color: rgba(255, 236, 232, 1);
  //   color: #ff7d00;
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  // }

  .order-info {
    width: 95%;
    margin: 20px auto;
  }

  :deep(.arco-form) {
    width: 90%;
  }

  // :deep(.arco-input-wrapper),
  // :deep(.arco-input[disabled]) {
  //   -webkit-text-fill-color: rgb(0, 0, 0);
  // }

  // :deep(.arco-picker-disabled),
  // :deep(.input[disabled]) {
  //   -webkit-text-fill-color: rgb(0, 0, 0);
  // }
</style>
